﻿<span style='font-size:11px; color:#000000; background:#ffffff; '><pre>
<span style='color:#800000; font-weight:bold; '>Protected</span> <span style='color:#800000; font-weight:bold; '>Sub</span> createPdfButton_Click<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>ByVal</span> sender <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Object</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>ByVal</span> e <span style='color:#800000; font-weight:bold; '>As</span> EventArgs<span style='color:#808030; '>)</span>
    <span style='color:#696969; '>' Get the PDF Standard</span>
    <span style='color:#696969; '>' By default the Full PDF standard is used</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfStandard <span style='color:#800000; font-weight:bold; '>As</span> PdfStandardSubset <span style='color:#808030; '>=</span> PdfStandardSubset<span style='color:#008c00; '>.</span>Full
    <span style='color:#800000; font-weight:bold; '>If</span> pdfARadioButton<span style='color:#008c00; '>.</span>Checked <span style='color:#800000; font-weight:bold; '>Then</span>
        pdfStandard <span style='color:#808030; '>=</span> PdfStandardSubset<span style='color:#008c00; '>.</span>Pdf_A_1b
    <span style='color:#800000; font-weight:bold; '>ElseIf</span> pdfXRadioButton<span style='color:#008c00; '>.</span>Checked <span style='color:#800000; font-weight:bold; '>Then</span>
        pdfStandard <span style='color:#808030; '>=</span> PdfStandardSubset<span style='color:#008c00; '>.</span>Pdf_X_1a
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>

    <span style='color:#696969; '>' Get the Color Space</span>
    <span style='color:#696969; '>' By default the RGB color space is used</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfColorSpace <span style='color:#800000; font-weight:bold; '>As</span> ColorSpace <span style='color:#808030; '>=</span> ColorSpace<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>RGB</span>
    <span style='color:#800000; font-weight:bold; '>If</span> grayScaleRadioButton<span style='color:#008c00; '>.</span>Checked <span style='color:#800000; font-weight:bold; '>Then</span>
        pdfColorSpace <span style='color:#808030; '>=</span> ColorSpace<span style='color:#008c00; '>.</span>Gray
    <span style='color:#800000; font-weight:bold; '>ElseIf</span> cmykRadioButton<span style='color:#008c00; '>.</span>Checked <span style='color:#800000; font-weight:bold; '>Then</span>
        pdfColorSpace <span style='color:#808030; '>=</span> ColorSpace<span style='color:#008c00; '>.</span>CMYK
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>

    <span style='color:#696969; '>' Create the PDF document</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfDocument <span style='color:#800000; font-weight:bold; '>As</span> Document <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>Nothing</span>

    <span style='color:#800000; font-weight:bold; '>If</span> pdfStandard <span style='color:#808030; '>=</span> PdfStandardSubset<span style='color:#008c00; '>.</span>Full AndAlso pdfColorSpace <span style='color:#808030; '>=</span> ColorSpace<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>RGB</span> <span style='color:#800000; font-weight:bold; '>Then</span>
        <span style='color:#696969; '>' Create a PDF document with default standard and color space</span>
        pdfDocument <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>New</span> Document<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Else</span>
        <span style='color:#696969; '>' Create a PDF document with the selected standard and color space</span>
        pdfDocument <span style='color:#808030; '>=</span> <span style='color:#800000; font-weight:bold; '>New</span> Document<span style='color:#808030; '>(</span>pdfStandard<span style='color:#808030; '>,</span> pdfColorSpace<span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>If</span>

    <span style='color:#696969; '>' Set license key received after purchase to use the converter in licensed mode</span>
    <span style='color:#696969; '>' Leave it not set to use the converter in demo mode</span>
    pdfDocument<span style='color:#008c00; '>.</span>LicenseKey <span style='color:#808030; '>=</span> <span style='color:#0000e6; '>"4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="</span>

    <span style='color:#696969; '>' Get the selected PDF page size</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPageSize <span style='color:#800000; font-weight:bold; '>As</span> PdfPageSize <span style='color:#808030; '>=</span> SelectedPdfPageSize<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Get the selected PDF page orientation</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPageOrientation <span style='color:#800000; font-weight:bold; '>As</span> PdfPageOrientation <span style='color:#808030; '>=</span> SelectedPdfPageOrientation<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Get the PDF page margins</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> pdfPageMargins <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> Margins<span style='color:#808030; '>(</span><span style='color:#800000; font-weight:bold; '>Single</span><span style='color:#008c00; '>.</span>Parse<span style='color:#808030; '>(</span>leftMarginTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>Single</span><span style='color:#008c00; '>.</span>Parse<span style='color:#808030; '>(</span>rightMarginTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>Single</span><span style='color:#008c00; '>.</span>Parse<span style='color:#808030; '>(</span>topMarginTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span><span style='color:#808030; '>)</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>Single</span><span style='color:#008c00; '>.</span>Parse<span style='color:#808030; '>(</span>bottomMarginTextBox<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Text</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

    <span style='color:#696969; '>' Create a PDF page in PDF document</span>
    <span style='color:#800000; font-weight:bold; '>Dim</span> firstPdfPage <span style='color:#800000; font-weight:bold; '>As</span> PdfPage <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>AddPage<span style='color:#808030; '>(</span>pdfPageSize<span style='color:#808030; '>,</span> pdfPageMargins<span style='color:#808030; '>,</span> pdfPageOrientation<span style='color:#808030; '>)</span>

    <span style='color:#800000; font-weight:bold; '>Try</span>
        <span style='color:#696969; '>' The URL of the HTML page to convert to PDF</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> urlToConvert <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>String</span> <span style='color:#808030; '>=</span> <span style='color:#0000e6; '>"http://www.evopdf.com"</span>

        <span style='color:#696969; '>' Create the HTML to PDF element</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> htmlToPdfElement <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>New</span> HtmlToPdfElement<span style='color:#808030; '>(</span>urlToConvert<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Optionally set a delay before conversion to allow asynchonous scripts to finish</span>
        htmlToPdfElement<span style='color:#008c00; '>.</span>ConversionDelay <span style='color:#808030; '>=</span> <span style='color:#008c00; '>2</span>

        <span style='color:#696969; '>' Add the HTML to PDF element to PDF document</span>
        firstPdfPage<span style='color:#008c00; '>.</span>AddElement<span style='color:#808030; '>(</span>htmlToPdfElement<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Save the PDF document in a memory buffer</span>
        <span style='color:#800000; font-weight:bold; '>Dim</span> outPdfBuffer<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span> <span style='color:#800000; font-weight:bold; '>As</span> <span style='color:#800000; font-weight:bold; '>Byte</span> <span style='color:#808030; '>=</span> pdfDocument<span style='color:#008c00; '>.</span>Save<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Send the PDF as response to browser</span>

        <span style='color:#696969; '>' Set response content type</span>
        Response<span style='color:#008c00; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Content-Type"</span><span style='color:#808030; '>,</span> <span style='color:#0000e6; '>"application/pdf"</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Instruct the browser to open the PDF file as an attachment or inline</span>
        Response<span style='color:#008c00; '>.</span>AddHeader<span style='color:#808030; '>(</span><span style='color:#0000e6; '>"Content-Disposition"</span><span style='color:#808030; '>,</span> <span style='color:#800000; font-weight:bold; '>String</span><span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Format</span><span style='color:#808030; '>(</span><span style='color:#0000e6; '>"attachment; filename=Create_PDF_Documents.pdf; size={0}"</span><span style='color:#808030; '>,</span> outPdfBuffer<span style='color:#008c00; '>.</span>Length<span style='color:#008c00; '>.</span>ToString<span style='color:#808030; '>(</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span><span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' Write the PDF document buffer to HTTP response</span>
        Response<span style='color:#008c00; '>.</span>BinaryWrite<span style='color:#808030; '>(</span>outPdfBuffer<span style='color:#808030; '>)</span>

        <span style='color:#696969; '>' End the HTTP response and stop the current page processing</span>
        Response<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>End</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>Finally</span>
        <span style='color:#696969; '>' Close the PDF document</span>
        pdfDocument<span style='color:#008c00; '>.</span><span style='color:#800000; font-weight:bold; '>Close</span><span style='color:#808030; '>(</span><span style='color:#808030; '>)</span>
    <span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Try</span>
<span style='color:#800000; font-weight:bold; '>End</span> <span style='color:#800000; font-weight:bold; '>Sub</span>
</pre>
</span>